package com.taikang.t.service.impl;

import java.util.List;
import java.util.Random;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taikang.common.util.hibernate.SimpleHibernateTemplate;
import com.taikang.t.model.FashionWord;

@Service
public class FashionWordManager {

	
	private SimpleHibernateTemplate<FashionWord, Long> fashionWordDAO;
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		fashionWordDAO = new SimpleHibernateTemplate<FashionWord, Long>(sessionFactory, FashionWord.class);
	}
	
	
	@SuppressWarnings("unchecked")
	public List findAnswers(String say)
	{
		return fashionWordDAO.find("from FashionWord where say like '%" + say + "%'");
	}
	
	@SuppressWarnings("unchecked")
	public String findAnswer(String say)
	{
		List answers = fashionWordDAO.find("from FashionWord where say like '%" + say + "%'");
		Integer count = answers.size();
		Random r = new Random(count);
		FashionWord fw = (FashionWord) answers.get(r.nextInt());
		return fw.getAnswer();
	}
	
}
